package com.aoxiang.zbox.controller;

import com.aoxiang.zbox.common.model.Result;
import com.aoxiang.zbox.model.dto.CreateTodoItemRequest;
import com.aoxiang.zbox.model.dto.UpdateSortDTO;
import com.aoxiang.zbox.model.dto.UpdateTodoItemRequest;
import com.aoxiang.zbox.model.entity.TodoItem;
import com.aoxiang.zbox.model.vo.GetDeletedVO;
import com.aoxiang.zbox.model.vo.LabelTodoItemVO;
import com.aoxiang.zbox.service.TodoItemService;
import com.aoxiang.zbox.service.TodoSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 *
 * @author: aoxiang
 * @create: 2025-03-08 20:20
 **/

@RestController
@RequestMapping("/api/todo-item")
public class TodoItemController {
    @Autowired
    private TodoItemService todoItemService;
    @Autowired
    private TodoSortService todoSortService;

    @PostMapping("/physical-delete")
    public Result<String> physicalDeletion(@RequestBody() List<Long> ids) {
        todoItemService.physicalDeletion(ids);
        return Result.success();
    }

    @GetMapping("/recover")
    public Result<TodoItem> recoverTodoItem(@RequestParam("id") Long id) {
        return Result.success(todoItemService.recoverTodoItem(id));
    }

    @PostMapping("/create")
    public Result<Long> createTodoItem(@RequestBody @Validated CreateTodoItemRequest request) {
        return Result.success(todoItemService.createTodoItem(request));
    }

    @GetMapping("/remove")
    public Result<String> removeTodoItem(@RequestParam("id") Long id) {
        todoItemService.removeTodoItem(id);
        return Result.success();
    }

    @PostMapping("/update")
    public Result<String> updateTodoItem(@RequestBody @Validated UpdateTodoItemRequest request) {
        todoItemService.updateTodoItem(request);
        return Result.success();
    }

    @PostMapping("/update-show-sort")
    public Result<String> updateShowSort(@RequestBody @Validated UpdateSortDTO updateSortDto) {
        todoSortService.updateShowSort(updateSortDto);
        return Result.success();
    }

    @PostMapping("/update-completed-sort")
    public Result<String> updateCompletedSort(@RequestBody @Validated UpdateSortDTO updateSortDto) {
        todoSortService.updateCompletedSort(updateSortDto);
        return Result.success();
    }

    @GetMapping("/get-shown")
    public Result<List<LabelTodoItemVO>> getShownTodoItem() {
        return Result.success(todoItemService.getShownTodoItem());
    }

    @GetMapping("/get-completed")
    public Result<List<LabelTodoItemVO>> getCompletedItem() {
        return Result.success(todoItemService.getCompletedItem());
    }

    @GetMapping("/get-deleted")
    public Result<List<GetDeletedVO>> getDeletedItem() {
        return Result.success(todoItemService.getDeletedItem());
    }
}
